<!-- 见证任务分配 -->
<template>
  <div class="layout-wrapper layout-witness">
    <div class="layout-body">
      <el-table
        v-loading="tableLoading"
        :data="tableData"
        highlight-current-row
        style="width: 100%"
        height="100%"
        header-row-class-name="out-Table-header"
      >
        <el-table-column type="index" label="序号" width="53" align="center" />
        <el-table-column prop="itemName" label="预警事项" min-width="223" show-overflow-tooltip />
        <el-table-column prop="warningLevel" label="预警级别" min-width="167" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ warningLevelObj[scope.row.warningLevel] }}
          </template>
        </el-table-column>
        <el-table-column prop="warningCategory" label="预警类别" min-width="158" show-overflow-tooltip />
        <el-table-column prop="warningBasis" label="预警依据" min-width="158" show-overflow-tooltip />
        <el-table-column prop="dataStatus" label="预警开关" min-width="159" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.dataStatus"
              active-text="开"
              inactive-text="关"
              active-color="#57B21C"
              active-text-color="#fff"
              inactive-color="#E5E5E5"
              inactive-text-color="#999999"
            />
          </template>
        </el-table-column>
        <el-table-column prop="pushSwitch" label="上报开关" min-width="159" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.pushSwitch"
              active-text="开"
              inactive-text="关"
              active-color="#57B21C"
              active-text-color="#fff"
              inactive-color="#E5E5E5"
              inactive-text-color="#999999 "
            />
          </template>
        </el-table-column>
        <!-- <el-table-column label="操作" min-width="160">
          <template slot-scope="scope"> -->
        <!-- <el-button
              type="text"
              @click="handleViewDetailFn(scope.row.projectId)"
            >
              查看
            </el-button>
            <el-button type="text" @click="handleCancelWitness(scope.row)">
              编辑
            </el-button>
            <el-button type="text" @click="handleCancelWitness(scope.row)">
              删除
            </el-button> -->
        <!-- </template>
        </el-table-column> -->
      </el-table>
    </div>
  </div>
</template>
<script>
  // 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
  import { witnessRecordDistributeList } from "../../../../api/api";
  export default {
    // 引入组
    props: {
      tableData: {
        type: Array,
        default: () => [],
        required: true
      },
      tableLoading: {
        type: String,
        default: "",
        required: true
      }
    },
    data() {
      // 这里存放数据
      return {
        warningLevelObj: {
          HEIGHT: "高",
          MIDDLE: "中",
          LOW: "低"
        },
        value: true
      };
    },
    // 监听属性 类似于data概念
    computed: {},
    // 监控data中的数据变化
    watch: {},
    // 生命周期 - 创建完成（可以访问当前this实例）
    created() {
      console.log(this.warningLevelList, "呃呃呃呃呃呃");
    },
    // 生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {},
    // 生命周期 - 销毁之前
    beforeDestroy() {},
    // 生命周期 - 销毁完成
    destroyed() {},
    // 如果页面有keep-alive缓存功能，这个函数会触发
    activated() {},
    // 方法集合
    methods: {
      // 见证审核记录列表查询
      async witnessRecordDistributeListFn() {
        try {
          this.tableLoading = true;
          this.tableData = [];
          const params = {
            industryList: this.searchForm.industrySecondLevel,
            tenderMode: this.searchForm.tenderMode,
            qualificationExamMethod: this.searchForm.zsType,
            search: this.searchForm.keywords,
            startTime: `${this.searchForm.date[0]} 00:00:00`,
            endTime: `${this.searchForm.date[1]} 23:59:59`,
            currentPage: this.pageObj.currentPage,
            pageSize: this.pageObj.pageSize
          };
          const res = await witnessRecordDistributeList(params);
          // console.log("assignData", assignData);
          // const res = assignData;
          this.tableLoading = false;
          if (res.success) {
            const arr = [];
            res.data.result.forEach((proItem) => {
              const proObj = proItem.data;
              proItem.pageOpers.forEach((val) => {
                proObj[val.code] = true;
              });
              proObj.bidList = [];
              proItem.data.bidSectionVOList.forEach((bidItem) => {
                const bidObj = this.$cafeUtils.deepClone(bidItem);
                this.$delete(bidObj, "witnessSubTaskVOList");
                let newBidObj = {};
                bidItem.witnessSubTaskVOList.result.forEach((witnessItem, index) => {
                  newBidObj = { ...bidObj, ...witnessItem.data };
                  witnessItem.pageOpers.forEach((val) => {
                    newBidObj[val.code] = true;
                  });
                  // 判断标段表格框是否变细，除了第一个均变细
                  if (index < bidItem.witnessSubTaskVOList.result.length - 1) {
                    newBidObj.thinBorder = true;
                  }
                  proObj.bidList.push(newBidObj);
                });
                // );
              });
              arr.push(proObj);
            });
            console.log("arr", arr);
            this.tableData = arr;
            this.pageObj.total = res.data.pageBean.count;
          } else {
            this.$message({
              type: "error",
              message: res.message || "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (error) {
          console.log(error);
          this.tableLoading = false;
        }
      }
    }
  };
</script>
<style lang="scss" scoped>
  .witness-result {
    width: 76px;
    height: 20px;
    line-height: 20px;
    background: #fc9306;
    border-radius: 10px;
    color: #fff;
    font-size: 12px;
    text-align: center;
  }
  .layout-witness .layout-search {
    background: #fff;
  }
</style>
